package subArray;

/**
 * 四、子数组问题
 * 1. 最大子数组和
 * 2024-10-27
 */

public class demo19 {
    public int maxSubArray(int[] nums) {
        int ret = Integer.MIN_VALUE;
        int n = nums.length;
        int[] dp = new int[n+1];

        dp[0] = 0;

        for (int i = 1; i <= n; i++) {
            dp[i] = Math.max(nums[i-1], dp[i-1] + nums[i-1]);
            ret = Math.max(ret, dp[i]);
        }
        return ret;
    }
}
